/**
 * @param {number[]} array
 * @return {number[]}
 */
var subSort = function(array) {
  // 正序遍历
  let pos = [];
  let last = array[0];
  let max = array[0], min = array[array.length - 1];
  for (let i = 1; i < array.length; i++) {
    const element = array[i];
    // 比前面数小，且小于已经遍历过的最小值
    if(element < last || element < max) {
      // 标记
      pos.push(i);
    }
    max = Math.max(max, element);
    last = element;
  }
  last = array[array.length - 1];
  let reversePos = [];
  for (let j = array.length - 1; j >= 0; j--) {
    const element = array[j];
    console.log(element, min);
    if(element > last || element > min) {
      reversePos.push(j);
    }
    min = Math.min(min, element);
    last = element;
  }
  return pos.length && reversePos.length ? [reversePos.pop(), pos.pop()] : [-1, -1]
  console.log(pos, reversePos)
};

subSort([1,2,4,7,10,11,7,12,6,7,16,18,19]);
subSort([1,2,4,7,10,11]);